<html>

			
			<?php
				$categoryId = $_GET ["categoryId"];
				$con = mysql_connect("localhost","root","");
				if (!$con)
				{
					die('Could not connect: ' . mysql_error());
				}

				$currentLetter = '';
				$newLetter = '';
				
				mysql_select_db("rgfusion", $con);

				$result = mysql_query("SELECT * FROM companies WHERE companycategory = " . $categoryId . " ORDER BY companyName");

				$indexText = "<div>";
				$mainText = "";
				
				while($row = mysql_fetch_array($result))
				{
					$companyName = $row["companyName"];
					$newLetter = $companyName[0];
				
					if ($newLetter != $currentLetter)
					{
						if ($currentLetter != '')
						{
							$mainText .= "</ul></div>";
						}

						$mainText .= '<div class = "clothesList">
							<a name="' . $newLetter . '"><h1>' . $newLetter . '</h1></a>
							<ul>';
						
						$currentLetter = $newLetter;
						
						$indexText .= '<a href = "#' . $currentLetter . '">' . $currentLetter . '</a>';
					}
					
					$mainText .= '<li><a href = "">' . htmlentities($row["companyName"]) . '</a></li>';
				}

				$indexText .= "</div>";
				
				if ($currentLetter != '')
				{
					$mainText .= "</ul></div>";
				}

				echo $indexText;
				echo $mainText;
				
				mysql_close($con);
			?>
		
</html>